﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MongoDB.Bson;
using M = MongoDB.Driver.Builders;

using TMS.ProjectServiceModel;

namespace TMS.ProjectServiceImplement.DAL
{
    public class ProjectPublishStatusDAL
    {
        public static List<PublishStatus> GetAllProjectStatus(int id)
        {
            List<PublishStatus> list = new List<PublishStatus>();

            var collection = DataAccess.GetPublishDB<PublishStatus>("ProjectStatus");
            var query = M.Query.EQ("ProjectId", new BsonInt32(id));
            var result = collection.Find(query);
            if (result != null)
            {
                foreach (var item in result)
                {
                    list.Add(item);
                }
            }

            return list;
        }

        public static PublishStatus Insert(PublishStatus status)
        {
            var collection = DataAccess.GetPublishDB<PublishStatus>("ProjectStatus");
            var result = collection.Insert<PublishStatus>(status);
            if (result.Ok)
            {
                return status;
            }
            else
            {
                return null;
            }
        }

        public static void Delete(int id)
        {
            var collection = DataAccess.GetPublishDB<PublishStatus>("ProjectStatus");
            collection.Remove(M.Query.EQ("ID", new BsonInt32(id)));
        }
    }
}
